<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018\10\28 0028
 * Time: 10:03
 */
namespace app\admin\controller;
use app\admin\model\Databases;
use think\Db;
use think\Request;

class Data
{
    /**普通模型添加
     * @param Request $request
     * @return string|\think\response\Redirect
     */
    public function add(Request $request){
        $modelid = $request->param('model',null);
        $data    = $request->post();
        if(!$modelid){
            return '请输入建造的模型id';
        }
        $model = Db::name('model')->where('id',$modelid)->find();
        $file = $request->file();
        $bool = Databases::add_data_p($model,$data,$file);
//        echo '<pre>';
//        print_r($bool);exit;
        if($bool){
            return redirect('document/err',['str'=>'添加成功','code'=>200]);
        }else{
            return redirect('document/err',['str'=>'添加失败','code'=>201]);
        }
    }
}